import random
import os

rand = 50
minimum = 1
maximum = 100
timesLimit = 20
count=0

def rootMenu():
	global rand,minimum,maximum,timesLimit,count
	
	while True:
		print('''Root Menu:
	Get:
		1.rand
		2.minimum
		3.maximum
		4.timesLimit
		5.count
	Set:
		6:rand
		7.minimum
		8.maximum
		9.timesLimit
		10.count
	Others:
		11.exit
		12.reset

Please choose an operation(inout its order):''')
		rootInp = input()
		if rootInp == "1":
			print("rand is:",rand)
		elif rootInp == "2":
			print("minimum is:",minimum)
		elif rootInp == "3":
			print("maximum is:",maximum)
		elif rootInp == "4":
			print("timesLimit is:",timesLimit)
		elif rootInp == "5":
			print("count is:",count)
		elif rootInp == "6":
			newRand = input("Please input rand:")
			if newRand.isdigit():
				rand = int(newRand)
			else:
				print("Invalid input.")
		elif rootInp == "7":
			newMinimum = input("Please input minimum:")
			if newMinimum.isdigit():
				minimum = int(newMinimum)
			else:
				print("Invalid input.")
		elif rootInp == "8":
			newMaximum = input("Please input maximum:")
			if newMaximum.isdigit():
				maximum = int(newMaximum)
			else:
				print("Invalid input.")
		elif rootInp == "9":
			newTimesLimit = input("Please input timesLimit:")
			if newTimesLimit.isdigit():
				timesLimit = int(newTimesLimit)
			else:
				print("Invalid input.")
		elif rootInp == "10":
			newCount = input("Please input count:")
			if newCount.isdigit():
				count = int(newCount)
			else:
				print("Invalid input.")
		elif rootInp == "11":
			return
		elif rootInp == "12":
			rand = random.randint(minimum,maximum)
			minimum = 1
			maximum = 100
			timesLimit = 20
		else:
			print("Unknown choice.")

			
			
os.system("title 猜数字游戏")
while True:
	print("猜数字游戏 随机生成一个1~100之间的数")
	print("您可以想猜的数字 输入系统会提示您是大了还是小了")
	print("快来看看你要猜多少次才能猜出来")
	print("PS: 输入exit可退出 输入refresh可重开局\n")
	rand = random.randint(minimum,maximum)
	count=0
	askRepeat = True
	win = False
	while count != timesLimit:
		if timesLimit >= 0:
			print("还剩",timesLimit-count,"次!")
			
		inp = input("请输入您猜的数:")
		
		if inp == "ROOT":
			rootMenu()
			continue
		elif inp == "exit":
			exit()
		elif inp == "refresh":
			askRepeat = False
			os.system("cls")
			break
			
		if inp.isdigit():
			inp = int(inp)
		else:
			print("输入有误!")
			continue

		count+=1
		if inp > rand:
			print("大了!")
		elif inp < rand:
			print("小了!")
		else:
			win = True
			print("您赢了!")
			print("您用了",count,"次!")
			print("\n\n\n\n")
			break
	if not win:
		print("次数已用完，您输了!")
	if askRepeat:
		repeat = input("是否重来?(y/n)")
		if repeat == "y":
			os.system("cls")
		else:
			break